package socketmvc.core.processor.bean.optimizer.ret;

import socketmvc.core.context.IContext;
import socketmvc.core.packets.basic.IPacket;
import socketmvc.core.packets.basic.impl.JsonBinPacket;
import socketmvc.core.packets.basic.impl.JsonTextBody;
import socketmvc.core.packets.biz.SockFile;
import socketmvc.core.packets.biz.SockMultiFile;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class DefRetFileArrValOptimizer extends DefAbstractRetOptimizer<File[]> {

    @Override
    public IPacket doValue(IContext context, IPacket packet, File[] files, JsonTextBody responseTextBody) {
        List<SockFile> sockFiles = new ArrayList<>(files.length);
        for (File file : files) {
            sockFiles.add(new SockFile(file));
        }
        SockMultiFile multiFile = new SockMultiFile(sockFiles);
        return new JsonBinPacket(responseTextBody , multiFile);
    }
}
